package com.cloudwise.gproject.controller;

import com.cloudwise.gproject.entity.Log;
import com.cloudwise.gproject.service.LogService;
import com.cloudwise.gproject.util.Result;
import com.cloudwise.gproject.util.ReturnStatus;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Log)表控制层
 *
 * @author makejava
 * @since 2021-03-22 13:28:07
 */
@Controller
@RequestMapping("log")
public class LogController {
    /**
     * 服务对象
     */
    @Resource
    private LogService logService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping("selectOne")
    public Log selectOne(Integer id) {
        return this.logService.queryById(id);
    }

    /**
     * @create by: 卫子健
     * @description: 跳转到部门管理页面dept.html?
     * @create time: 2021/3/19 19:45
     */
    @RequestMapping("toLog1")
    public String toLog1() {
        return "back/log1";
    }

    /**
     * @return com.cloudwise.trademark.util.Result?
     * @create by: 卫子健
     * @description: 分页条件查询所有部门列表?
     * @create time: 2021/3/19 20:35
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result queryAll(Integer page, Integer limit, Log log) {
        PageInfo pageInfo = logService.queryAll(page, limit, log);
        System.out.println(log);
        System.out.println(pageInfo.getList().size());
        System.out.println(pageInfo.getList());
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }

    @ResponseBody
    @RequestMapping("queryYear")
    public Result queryYear() {
        List<String> years = logService.queryYear();
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, years);
    }
    @ResponseBody
    @RequestMapping("queryShowChartData")
    public Result queryShowChartData(Integer year,Integer month){
        System.out.println(year+"llllllllllll"+month);
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.logService.queryShowChartData(year,month));
    }
}
